dofile(getDataDir() .. 'actions/lib/crafting.lua')

ROPE_SPOT = {384, 418, 8278, 8592}
OPENED_HOLE = {294, 383, 392, 469, 470, 482, 484, 485, 489, 7933, 7938, 8249, 8250, 8251, 8252, 8253, 8254, 8255, 8256, 8323, 8380, 8567, 8585, 8972}
CLOSED_HOLE = {468, 481, 483, 7932, 8579}
OPENED_TRAP = {462, 9625}
DOWN_LADDER = {369, 370, 408, 409, 427, 428, 430, 924, 3135, 3136, 5545, 5763, 8170, 8276, 8277, 8279, 8280, 8281, 8284, 8285, 8286, 8595, 8596, 9606}
JUNGLE_GRASS_TRANSFORM = {2782, 3985}
JUNGLE_GRASS_REMOVE = {1499}
SPIDER_WEB = {7538, 7539}

WATER = {490, 4608, 491, 492, 493, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627,
628, 629, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621,
4622, 4623, 4624, 4625, 4664, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}

SWAMP = {602, 603, 604, 605, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4749, 4750, 4751, 4752, 4753, 4754, 4755, 4758}

OVEN_ON = {1786, 1788, 1790, 1792, 6356, 6358, 6360, 6362}
LADDER = {1386, 3678, 5543, 8599}
DECAYTO_ITEM_INCREMENT = {2041, 2044, 2047, 2050, 2052, 2054, 5812, 7183, 9006}

LOCKED_DOORS = {1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 5107, 5116, 5125, 5134, 5137, 5140, 5143, 5278, 5281, 5732, 5735, 6192, 6195, 6249, 6252, 6891, 6900, 7033, 7042, 8541, 8544, 9165, 9168, 9267, 9270, 10268, 10271, 10468, 10477}

CONSTRUCTIONS = {
	[3901] = 1650, [3902] = 1658, [3903] = 1666, [3904] = 1670, [3905] = 3813, [3906] = 3817, [3907] = 2093, [3908] = 2603, [3909] = 1614, [3910] = 1615,
	[3911] = 1616, [3912] = 1619, [3913] = 3805, [3914] = 3807, [3915] = 1740, [3916] = 1774, [3917] = 2084, [3918] = 2095, [3919] = 3809, [3920] = 3832,
	[3921] = 1714, [3922] = 2107, [3923] = 2104, [3924] = 7670, [3925] = 1740, [3926] = 2080, [3927] = 2098, [3928] = 1676, [3929] = 2101, [3930] = 1739,
	[3931] = 2105, [3932] = 1724, [3933] = 1728, [3934] = 1732, [3935] = 1775, [3936] = 3812, [3937] = 2064, [3938] = 6371, [5086] = 1738, [5087] = 1741, [5088] = 1770,
	[6114] = 2106, [6115] = 2034, [6372] = 3811, [6373] = 1736, [7503] = 1750, [7700] = 5928, [7960] = 3821, [7961] = 3811, [7962] = 2582, [8692] = 8688, [8693] = 7486
}

FOODS = {
	[2328] = {84, "Gulp."},	[2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
	[2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
	[2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
	[2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
	[2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
	[2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
	[2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
	[2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [2769] = {60, "Crunch."}, [2787] = {108, "Crunch."},
	[2788] = {48, "Crunch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
	[2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
	[2796] = {300, "Crunch."}, 	[5097] = {48, "Yum."}, [5678] = {96, "Gulp."}, [6125] = {96, "Mmmm."},
	[6278] = {120, "Mmmm."}, [6279] = {180, "Mmmm."}, [6393] = {144, "Mmmm."}, [6394] = {180, "Mmmm."},
	[6501] = {240, "Mmmm."}, [6541] = {72, "Gulp."}, [6542] = {72, "Gulp."}, [6543] = {72, "Gulp."},
	[6544] = {72, "Gulp."}, [6545] = {72, "Gulp."}, [6569] = {12, "Mmmm."}, [6574] = {60, "Mmmm."},
	[7158] = {300, "Munch."}, [7159] = {180, "Munch."}, [7372] = {0, "Yummy."}, [7373] = {0, "Yummy."},
	[7374] = {0, "Yummy."},	[7375] = {0, "Yummy."}, [7376] = {0, "Yummy."}, [7377] = {0, "Yummy."},
	[7963] = {720, "Munch."},  [8838] = {120, "Gulp."}, [8839] = {60, "Yum."}, [8840] = {12, "Yum."},
	[8841] = {12, "Urgh."}, [8842] = {84, "Munch."}, [8843] = {60, "Crunch."}, [8844] = {12, "Gulp."},
	[8845] = {60, "Munch."}, [8847] = {132, "Yum."}, [9005] = {88, "Slurp."}, [9996] = {0, "Slurp."},
	[10454] = {0, "Your head begins to feel better."}, [11136] = {120, "Mmmm."}, [11246] = {180, "Yum."},
	[11370] = {36, "Urgh."}
}

SPECIAL_FOODS = {
	[9992] = {"Gulp."}, [9993] = {"Chomp."}, [9994] = {"Chomp."}, [9995] = {"Chomp."}, [9997] = {"Yum."},
	[9998] = {"Munch."}, [9999] = {"Chomp."}, [10000] = {"Mmmm."}, [10001] = {"Smack."}

}

DISTILLERY = {5469, 5470, 5513, 5514}
DISTILLERY_FULL = 600

SMALL_SAPPHIRE	= 2146
SMALL_RUBY	= 2147
SMALL_EMERALD	= 2149
SMALL_AMETHYST	= 2150

ENCHANTED_SMALL_SAPPHIRE = 7759
ENCHANTED_SMALL_RUBY     = 7760
ENCHANTED_SMALL_EMERALD  = 7761
ENCHANTED_SMALL_AMETHYST = 7762

ENCHANTABLE_WEAPONS = {
	[2383] = {7744, 7763, 7869, 7854, 1000}, [7383] = {7745, 7764, 7870, 7855, 1000}, [7384] = {7746, 7765, 7871, 7856, 1000},
	[7406] = {7747, 7766, 7872, 7857, 1000}, [7402] = {7748, 7767, 7873, 7858, 1000}, [2429] = {7749, 7768, 7874, 7859, 1000},
	[2430] = {7750, 7769, 7875, 7860, 1000}, [7389] = {7751, 7770, 7876, 7861, 1000}, [7380] = {7752, 7771, 7877, 7862, 1000},
	[2454] = {7753, 7772, 7878, 7863, 1000}, [2423] = {7754, 7773, 7879, 7864, 1000}, [2445] = {7755, 7774, 7880, 7865, 1000},
	[7415] = {7756, 7775, 7881, 7866, 1000}, [7392] = {7757, 7776, 7882, 7867, 1000}, [2391] = {7758, 7777, 7883, 7868, 1000},
	[8905] = {8906, 8907, 8908, 8909}, [9934] = {}, [9949] = {}, [9954] = {}, [10022] = {}
}

MUSICAL_INSTRUMENTS = {2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2332, 2364, 2367, 2368, 2370, 2371, 2372, 2373, 2374, 3951, 3953, 3957}

NORTH_BEDS = {1754, 1758, 1762, 1766, 3836, 3840, 5496, 5500, 7778, 7781, 7785, 7786, 7791, 7795, 7799, 7803, 7807, 7811, 7815, 7819, 7841}
SOUTH_BEDS = {1755, 1759, 1763, 1767, 3837, 3841, 5497, 5501, 7782, 7788, 7790, 7792, 7796, 7800, 7804, 7808, 7812, 7816, 7820, 7842, 8075, 8077}
WEST_BEDS = {1756, 1760, 1764, 1768, 3838, 3842, 5498, 5502, 7779, 7783, 7786, 7789, 7793, 7797, 7801, 7805, 7809, 7813, 7817, 7821, 7843}
EAST_BEDS = {1757, 1761, 1765, 1769, 3839, 3843, 5499, 5503, 7780, 7784, 7794, 7798, 7802, 7806, 7810, 7814, 7818, 7822, 8076, 8078}

BREAKABLE_BY_WEAPONS = {
	[1619] = { remainings = 2255, chance = 15 },
	[1650] = { remainings = 2253, chance = 20 },
	[1651] = { remainings = 2253, chance = 20 },
	[1652] = { remainings = 2253, chance = 20 },
	[1653] = { remainings = 2253, chance = 20 }, 
	[3798] = { remainings = 3959, chance = 20 }, 
	[3799] = { remainings = 3958, chance = 20 },
}

function onUseWeapon(cid, item, frompos, item2, topos)
	local t = getItemWeaponTypeByUID(item.uid)
	if BREAKABLE_BY_WEAPONS[item2.itemid] ~= nil and ((t == WEAPON_SWORD) or (t == WEAPON_CLUB) or (t == WEAPON_AXE)) then
		local chance = BREAKABLE_BY_WEAPONS[item2.itemid].chance or 20
		if math.random(100) <= chance then
			doTransformItem(item2.uid, BREAKABLE_BY_WEAPONS[item2.itemid].remainings)
			doDecayItem(item2.uid)
			if item2.actionid ~= 0 then
				doSetItemActionId(item2.uid, item2.actionid)
			end
		end
		doSendMagicEffect(topos, CONST_ME_POFF)
		return true
	end
	
	if isInArray(SPIDER_WEB, item2.itemid) then
		doTransformItem(item2.uid, item2.itemid + 6)
		doDecayItem(item2.uid)
		return true
	end
	
	if item2.itemid == 7537 then --- spider egg
		doSendMagicEffect(topos,CONST_ME_BLOCKHIT)
		doTransformItem(item2.uid, 7536)
		doSummonCreature("Spider", topos)
		return true
	end

	return false
end

